package cn.z2huo.algorithm.binarytree;

import java.util.LinkedList;
import java.util.Queue;

// 求二叉树的最大深度
public class MaximumDepth {
    public int getMaxDepth(TreeNode root){
        if(root==null){
            return 0;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int result = 0;
        while (!queue.isEmpty()){
            int count = queue.size();
            while (count>0){
                TreeNode node = queue.poll();
                if (node.getLeft()!=null)   queue.offer(node.getLeft());
                if (node.getRight()!=null)  queue.offer(node.getRight());
                count --;
            }
            result ++;
        }
        return result;
    }

    public static void main(String[] args){
        BinaryTree bt = new BinaryTree();
        int[] array = {1,2,3,4,5,0,0,0,0,6,7};
//        int[] array = {};
        TreeNode root = bt.createTree(array);

        MaximumDepth md = new MaximumDepth();
        System.out.println(md.getMaxDepth(root));
    }
}
